package com.blacktry.controller;

import com.blacktry.entity.enums.OprLogConst;
import com.blacktry.entity.model.ApiResult;
import com.blacktry.service.OCRService;
import com.blacktry.utils.ApiResultHandler;
import com.blacktry.utils.log.OperLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.List;

@Controller
@RequestMapping("/Ocr")
@Api(value="OCR类模块", description = "阿里云OCR", tags = "阿里云OCR管理接口")
public class OCRController {
    @Autowired
    private OCRService ocrService;


    @OperLog(operModul = "OCR类模块-CR图片文字识别",operType = OprLogConst.SELECT,operDesc = "CR图片文字识别")
    @ApiOperation(value = "OCR图片文字识别", notes = "OCR图片文字识别", httpMethod = "POST")
    @RequestMapping(value = "/scanFileByFile", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult<List<String>> scanFileByFile(File file) throws Exception {
        return ApiResultHandler.buildApiResult(200,"成功",ocrService.scanByFile(file));
    }


    @OperLog(operModul = "OCR类模块-OCR图片文字识别根据URL",operType = OprLogConst.SELECT,operDesc = "OCR图片文字识别根据URL")
    @ApiOperation(value = "OCR图片文字识别根据URL", notes = "OCR图片文字识别", httpMethod = "POST")
    @RequestMapping(value = "/scanFileByUrl", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult<List<String>> scanFileByUrl(String url) throws Exception {
        return ApiResultHandler.buildApiResult(200,"成功",ocrService.scanByUrl(url));
    }


    @OperLog(operModul = "OCR类模块-OCR图片文字识别根据URL",operType = OprLogConst.SELECT,operDesc = "OCR图片文字识别根据URL")
    @ApiOperation(value = "OCR图片文字识别根据URL", notes = "OCR图片文字识别", httpMethod = "POST")
    @RequestMapping(value = "/scanFileByUrls", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult<List<String>> scanFileByUrls(String[] urls) throws Exception {
        return ApiResultHandler.buildApiResult(200,"成功",ocrService.scanByUrls(urls));
    }

    @OperLog(operModul = "OCR类模块-OCR图片文字识别test",operType = OprLogConst.SELECT,operDesc = "OCR图片文字识别test")
    @ApiOperation(value = "OCR图片文字识别test", notes = "OCR图片文字识别", httpMethod = "POST")
    @RequestMapping(value = "/scanFileByMultipartFile", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult<List<String>> scanFileByMultipartFile(MultipartFile file) throws Exception {
        return ApiResultHandler.buildApiResult(200,"成功",ocrService.scanFileByMultipartFile(file));
    }
}